from jsonpath_rw import parse ,jsonpath
# from  jsonpath import jsonpath
from  jsonpath_rw.jsonpath import JSONPath
# def get_key_from_data(depend,data):
#     # 定义匹配规则
#     # tw="1888"
#     # ke="$..uid"
#     tt="2323"
#     # jsonexpr=parse(key)
#     # # print(jsonexpr.update(data,"211"))
#     # # result=json_expr.update(data,tw)
#     # result=jsonexpr.find(data)
#     # # print(data)
#     # # return  jsonexpr.update(data,"211")
#     # # [match.value for match in male][0]
#     # return [match.value for match in result]
#     jsonexe=parse(depend)
#     model=jsonexe.find(data)
#     return [match.value for match in model]
#     # print()
#
#
# if __name__ == '__main__':
#     # key="msg"
#     # key="data[*].uid"
#     # key="$..uidt"
#     # data={"code":"00","msg":"success","data":[
#     #     {"uidt":"1","name":"zs","age":11},
#     #     {"uid": "2", "name": "ls", "age": 12},
#     #     {"uid": "3", "name": "ww", "age": 13}
#     # ]}
#     data={
#         "Code":200,
#         "ErrorMessage":"0",
#         "Data":{"cartTypt":"0",
#                 "CartId":"23123123"}
#     }
#     depend='Data.Data.CartId'
#     print(get_key_from_data(depend))

data={
        "Code":200,
        "ErrorMessage":"0",
        "Data":{"cartTypt":"0",
                "CartId":"23123123",
                "Data":{"cartType":0,
                        "CartId":"23123123"}}
    }
depend='Date.Date.CartId'
jsonexe=parse(depend)
model=jsonexe.find(data)
print([match.value for match in model])